<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const mul = (x) => {
            let sum = x
            let curried = (y) => {
                sum = sum * y
                return curried
            }
            curried.toString = () => sum
            return curried
        }

        console.log(mul(1)) //1
        console.log(mul(1)(2))//2
        console.log(mul(1)(2)(3))//6
        console.log(mul(1)(2)(3)(4))//24

        var add = function (m) {
            var temp = function (n) {
                return add(m + n);
            }
            temp.toString = function () {
                return m;
            }
            return temp;
        };
        console.log(add(3)(4)(5)); // 12
        console.log(add(3)(6)(9)(25)); // 43
    </script>
</body>

</html>